var vue;
var vue3
function vue_init() {
    vue = new Vue({
        delimiters:['{!', '!}'],
        el: "#market-app",
        data: {
			assets:1000,//资产
            assetsTyple:'BNB',//资产类型
            CoinDetail: {},
            coin_type:"",
            depositAddress: "",
            img_url: "",
        },
        methods:{
            init: function () {
                var params = get_url_params()
                // console.log(" get coin_type " + params['coin_type'])
                // console.log(params.coin_type);
                this.get_coin_type(params.coin_type);
                this.coin_type = params.coin_type;
                this.get_deposit_address(this.coin_type);
            },
			openview:function(){
				layer.open({
					className:'depositlist',
					type: 1,
					content: $("#testbox").html(),
					anim: 'up',
					style: 'background: #12161C;color: #f3f3f3;position:fixed; left:0; top:0; width:100%; height:100%; border: none; -webkit-animation-duration: .5s; animation-duration: .5s;'
				});
				vue3_init();
			},
			to_test:function(){
				alert('888');
			},
			copy:function(){
				var clipboard = new ClipboardJS('.copybtn', {
					target: function(trigger) {
						//return trigger.nextElementSibling;
						return document.querySelector('.asset-address');
					}
				});
				//console.log(clipboard);
				clipboard.on('success', function(e) {
					e.clearSelection();
					  layer.open({
						  type:0,
						content: '成功',
						className:'cgong',
						skin: 'msg',
						style: 'border:none; background-color:#fff; color:#333;width:115px;border-radius:0px',
						time: 2 //2秒后自动关闭
					});
				});
				
			},
			openQRcode:function(){
				layer.open({
					className:'QRcodeBox',
					type: 1,
					content: $("#QRcode").html(),
					anim: 'up',
					style: 'background:none;color: #f3f3f3;position:fixed; left:0; top:0; width:100%; height:100%; border: none; -webkit-animation-duration: .5s; animation-duration: .5s;'
				});
                this.drawQRcode();

                $("#depositImg").attr("src", "data:image/gif;base64,"+ this.img_url);
                $("#a1").html(this.depositAddress);
			},
			drawQRcode:function(){
				var canvas=document.getElementById("cvs");
				var image=new Image();
				image.src="http://www.nbapp.cn:8080/images/BNB_address.png";
				image.onload=function(){
				canvas.getContext("2d").drawImage(this, 0, 0,200,200);
				};
				
				//alert('33');
			},

            /* 根据类型获取图标和名称 */
            get_coin_type: function (coin_type) { 
                /* 发送请求 */
                $.get("/m/get_balance", {
                    coin_type: coin_type
                }, (data) => {
                    this.CoinDetail = data;
                    /* 图标类型 */
                    var coin_info = get_coin_info(data.coin_type);
                    /* 图标样式 */
                    this.CoinDetail.img = get_coin_icon_url(data.coin_type);
                    this.CoinDetail.name_upper = coin_info.name_upper;
                });
            },

            /* 根据类型获取充值地址 */
            get_deposit_address: function (coin_type) { 
                /* 发送请求 */
                $.post("/btc/deposit", {
                    coin_type: coin_type
                }, (data) => {
                    // console.log(data);
                    this.depositAddress = data.address || "暂无地址";
                    this.img_url = data.base64_img
                });
            },

            /* 跳转到历史记录页面 */
            to_history: function (coin_type) { 
                window.location.href = './history?coin_type=' + coin_type;
            }
        }
    });
    vue.init();
}
var CoinList=[
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
	{"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
	{"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
	{"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    {"Coin_name":"ADA","L_name":"Cardano"},
    ];
function vue3_init() {
	vue3=new Vue({
        el: "#dataList",
        delimiters:['{!', '!}'],
		data: {
            c_data: CoinList,
            actData: CoinList,
		},
		methods:{
            init: function () { 
                this.get_all_coin();
            },
			select_coin: function(coin_type){
				vue.$data.assetsTyple=coin_type;//VUE间传值
				layer.closeAll();
                this.$destroy();
                window.location.href = "./deposit?coin_type=" + coin_type;
            },
            /* 根据类型获取图标和名称 */
            get_all_coin: function() {
                /* 发送请求，获取所有数据 */
                $.post("/btc/get_balances", {}, data => {
                //   console.log(data);d bs 
                  var show_data = [];
                  for (i = 0; i < data.length; i++) {
                    var item = data[i];
                    // console.log(item)
                    var info = {};
                    /* 图标类型 */
                    var coin_info = get_coin_info(item.coin_type);
                    // console.log(coin_info)
                    /* 图标样式 */
                    info.img = get_coin_icon_url(item.coin_type);
                    // console.log("["+info.img+"]")
                    info.coin_type = item.coin_type;
                    info.amount = item.amount;
                    info.name_upper = coin_info.name_upper;
                    info.full_name = coin_info.cname;
                    info.is_hidden = false;
                    show_data.push(info);
                  }
                  this.actData = show_data;
                });
            },

		},

    })
    vue3.init();
}		

$(function () {
    vue_init();
})